/**
 * @file Bsp.h
 * @author 徐松亮 (5387603@qq.com)
 * @version 1.0
 * @date 2023-09-28
 *
 * @copyright Copyright (c) {2030}  沈阳迈思医疗科技有限公司
 *
 * @brief 驱动层-->根据应用需求定义实体与初始化
 * @note (仅在h文件描述注释)
 * 	@verbatim
    1.适用芯片:无
    2.移植步骤:无
    3.验证方法:无
    4.使用方法:无
    5.其他说明:无
    @endverbatim
 * @todo 将接口尽量提取到H文件
 * @par 修改日志:
 * <table>
 * <tr><th>日期   <th>版本 <th>作者  <th>描述
 * <tr><td>2023-09-28 <td>1.0     <td>徐松亮     <td>创建初始版本
 * </table>
 */
/* 防止重复编译 (Define to prevent recursive inclusion)------------------------*/
#ifndef __BSP_FILE_H
#define __BSP_FILE_H
/* 通用头部文件 (General Includes)---------------------------------------------*/
/* 公有类型定义 (Exported types)-----------------------------------------------*/
/* 移植性宏定义 (Transplant define)--------------------------------------------*/
#if (defined(PROJECT_SYMS_DP))
//---->
#include "SEGGER_RTT.h"
#include "main.h"
#include "Bsp_Pwr.h"
#include "Bsp_Dwt.h"
#include "Module_Debug.h"
#include "Bsp_Led.h"
#include "Bsp_Key.h"
#include "Bsp_GpioIIC.h"
#include "Bsp_BkpRam.h"
#include "Bsp_Rtc.h"
#include "Bsp_Dac.h"
#include "Bsp_Adc.h"
#include "Bsp_Uart.h"
#include "Bsp_UsbHost_UDisk.h"
#include "Bsp_TfCard.h"
#include "Bsp_Sdp500.h"
#include "Bsp_KeyEncoder.h"
#include "Bsp_AirFan.h"
#include "Bsp_Ocs3fa.h"
#include "Bsp_Bmp280.h"
#include "Bsp_CpuFlash.h"
#include "Bsp_ConfigScreen.h"
#include "Bsp_Ltc4015.h"
#include "Bsp_SpO2.h"
#include "Bsp_Nebulizer.h"
#include "Bsp_Fan.h"
#include "Bsp_ProportionalValves.h"
#include "Bsp_Ds1339.h"
#include "Bsp_Alarm.h"
#include "Bsp_AirFan.h"
#include "Bsp_Sfm3000.h"
#include "Bsp_Bq4050.h"
#include "Bsp_ETCO2.h"
#include "Bsp_ABPDANN150PGAA5.h"
#include "Bsp_MPXV4006GC6U.h"
#include "Bsp_MPXV70xxGC6U.h"
#include "Bsp_AirFan.h"
#include "Bsp_Cpu.h"
#include "Bsp_Eeprom.h"
#include "Module_OS.h"
#include "Module_Debug.h"
#include "Module_Unity.h"
#include "App_Debug.h"
#include "App_Version.h"
#include "Module_Aes128.h"
//
extern uint32_t Main_TaskStart_Cmt;
extern uint32_t Main_TaskDebug_Cmt;
extern uint32_t Main_TaskGui_Cmt;
extern uint32_t Main_TaskControl_Cmt;
extern TIM_HandleTypeDef htim7;
extern void Bootloader_PreToStBoot(void);
// #define BSP_DEBUG_OUT_STR(str) DebugOutStr(str)
//  todo:优化

#define BSP_ADC_PRESS_OUT 0
#define BSP_ADC_VOLTAGE_PCBVIN 1
#define BSP_ADC_PRESS_O2 2
#define BSP_ADC_PRESS_ESOPHAGEAL 3
#define BSP_ADC_VOLTAGE_ACDC 4
#define BSP_ADC_TEMP_AIRFAN 5
#define BSP_ADC_PRESS_MASK 6
#define BSP_ADC_VOLTAGE_INT 7
#define BSP_ADC_VOLTAGE_BAT 8
#define BSP_ADC_VOLTAGE_SYS 9

#define BSP_ADC1_DMA_CHANNEL_MAX 10
#define BSP_ADC3_DMA_CHANNEL_MAX 3
#define BSP_ADC_REFERENCE_MV (2500)
#define BSP_AD_RESOLUTION (16)
#define BSP_AD_CPU_TEMP_CHANNEL (BSP_ADC3_DMA_CHANNEL_MAX - 3)
#define BSP_AD_CPU_VREFINT_CHANNEL (BSP_ADC3_DMA_CHANNEL_MAX - 2)
#define BSP_AD_CPU_VBAT (BSP_ADC3_DMA_CHANNEL_MAX - 1)

#define BSP_ABPDANN150PGAA5_ADC_TO_MV(_adc_16bit) 2 * BSP_ADC_CONVERT_TO_MV(_adc_16bit)
//
extern TIM_HandleTypeDef htim4;
#define BSP_AIRFAN_FREQ_TIMX &htim4
//
// #define BSP_BMP280_IIC_CH BSP_GPIO_IIC_4_CH
//
// #define BSP_SDP500_IIC_CH_OUT BSP_GPIO_IIC_3_CH
// #define BSP_SDP500_IIC_CH_O2 BSP_GPIO_IIC_2_CH
//
// #define BSP_SFM3000_IIC_CH BSP_GPIO_IIC_7_CH
//
// #define BSP_LTC4015_IIC_CH BSP_GPIO_IIC_5_CH
//
// #define BSP_BQ4050_IIC_CH BSP_GPIO_IIC_5_CH
//
#define BSP_KEY1_PORT GPIO_KEY1_GPIO_Port
#define BSP_KEY1_PIN GPIO_KEY1_Pin
#define BSP_KEY2_PORT GPIO_KEY2_GPIO_Port
#define BSP_KEY2_PIN GPIO_KEY2_Pin
//
#define BSP_LED_LED1_PORT GPIO_LED1_GPIO_Port
#define BSP_LED_LED1_PIN GPIO_LED1_Pin
#define BSP_LED_LED2_PORT GPIO_LED2_GPIO_Port
#define BSP_LED_LED2_PIN GPIO_LED2_Pin
#define BSP_LED_LED3_PORT GPIO_LED3_CHARGING_GPIO_Port
#define BSP_LED_LED3_PIN GPIO_LED3_CHARGING_Pin
#define BSP_LED_LED4_PORT GPIO_LED4_RED_GPIO_Port
#define BSP_LED_LED4_PIN GPIO_LED4_RED_Pin
#define BSP_LED_LED5_PORT GPIO_LED5_GREEN_GPIO_Port
#define BSP_LED_LED5_PIN GPIO_LED5_GREEN_Pin
#define BSP_LED_LED6_PORT GPIO_LED6_BLUE_GPIO_Port
#define BSP_LED_LED6_PIN GPIO_LED6_BLUE_Pin
//
#define BSP_LPUART_1_TXBUF_SIZE 256 // 32*N
#define BSP_LPUART_1_RXBUF_SIZE 256 // 32*N
#define BSP_UART_1_TXBUF_SIZE 256   // 32*N
#define BSP_UART_1_RXBUF_SIZE 256   // 32*N
#define BSP_UART_3_TXBUF_SIZE 256   // 32*N
#define BSP_UART_3_RXBUF_SIZE 256   // 32*N
#define BSP_UART_6_TXBUF_SIZE 256   // 32*N
#define BSP_UART_6_RXBUF_SIZE 256   // 32*N
#define BSP_UART_8_TXBUF_SIZE 256   // 32*N
#define BSP_UART_8_RXBUF_SIZE 256   // 32*N
//<----
#else
//---->
#error Please Set Effective Project to Bsp.h
//<----
#endif
/* 应用性宏定义 (Application define)-------------------------------------------*/
#define BSP_ADC_CONVERT_TO_MV(ad_value) ((ad_value * BSP_ADC_REFERENCE_MV) / ((1 << BSP_AD_RESOLUTION) - 1))
#define BSP_ADC_CONVERT_TO_ADC(mv) (((1 << BSP_AD_RESOLUTION) - 1) * mv / BSP_ADC_REFERENCE_MV)
/* 公有常量声明 (Exported constants)-------------------------------------------*/
/* 公有变量声明 (Exported variables)-------------------------------------------*/
//extern BSP_UART_T_INTERFACE Bsp_t_LpUart;
//extern BSP_UART_T_INTERFACE Bsp_t_Uart1;
//extern BSP_UART_T_INTERFACE Bsp_t_Uart3;
//extern BSP_UART_T_INTERFACE Bsp_t_Uart6;
//extern BSP_UART_T_INTERFACE Bsp_t_Uart8;
//extern BSP_DWT_T_INTERFACE Bsp_t_Dwt;
//extern BSP_KEY_T_INTERFACE Bsp_t_Key1;
//extern BSP_KEY_T_INTERFACE Bsp_t_Key2;
//extern BSP_LED_T_INTERFACE Bsp_t_Led1;
extern BSP_LED_T_INTERFACE Bsp_t_Led2;
extern BSP_LED_T_INTERFACE Bsp_t_Led3;
extern BSP_LED_T_INTERFACE Bsp_t_Led4;
extern BSP_LED_T_INTERFACE Bsp_t_Led5;
extern BSP_LED_T_INTERFACE Bsp_t_Led6;
#if 0
extern BSP_ABPDANN150PGAA5_T_INTERFACE Bsp_t_ABPDANN150PGAA5;
extern BSP_CPU_T_INTERFACE Bsp_t_Cpu;
extern BSP_OCS3FA_T_INTERFACE Bsp_t_Ocs3fa_Pipe;
extern BSP_OCS3FA_T_INTERFACE Bsp_t_Ocs3fa_Environment;
extern BSP_EEPROM_T_INTERFACE Bsp_t_Eeprom;
extern BSP_SDP500_T_INTERFACE Bsp_t_Sdp800_Out;
extern BSP_SDP500_T_INTERFACE Bsp_t_Sdp800_O2;
extern BSP_SFM3000_T_INTERFACE Bsp_t_SFM3000;
extern BSP_ALARM_T_INTERFACE Bsp_t_AlarmCPU;
extern BSP_BMP280_T_INTERFACE Bsp_t_Bsp280;
extern BSP_BQ4050_T_INTERFACE Bsp_t_Bq4050;
extern BSP_DS1339_T_INTERFACE Bsp_t_Ds1339;
extern BSP_AIRFAN_T_INTERFACE Bsp_t_AirFan;
extern BSP_SPO2_T_INTERFACE Bsp_SpO2_s_Data;
extern BSP_PROPORTIONAL_VALVES_T_INTERFACE Bsp_t_ProportionalValves;
extern BSP_ETCO2_T_INTERFACE Bsp_EtCO2_s;
extern BSP_FAN_T_INTERFACE Bsp_t_Fan;
extern BSP_NEBULIZER_T_INTERFACE Bsp_t_Nebulizer;
extern BSP_LTC4015_T_INTERFACE Bsp_t_Ltc4015Interface;
extern BSP_MPXV4006GC6U_T_INTERFACE Bsp_t_MPXV4006GC6U_Out;
extern BSP_MPXV4006GC6U_T_INTERFACE Bsp_t_MPXV4006GC6U_Mask;
extern BSP_MPXV70XXGC6U_T_INTERFACE Bsp_t_MPXV70xxGC6U;
//
extern MODULE_DEBUG_T_INTERFACE Bsp_t_ModuleDebug;
extern MODULE_UNITY_T_INTERFACE Bsp_t_ModuleUnity;
//
extern uint16_t BspAdc1_DmaBuf[BSP_ADC1_DMA_CHANNEL_MAX];
extern uint16_t BspAdc3_DmaBuf[BSP_ADC3_DMA_CHANNEL_MAX];
extern int8_t BspAdc_CpuTemp;
extern uint16_t BspAdc_Vrefint_mv;
extern uint16_t BspAdc_Vbat_mV;
#endif //0302 add
/* 公有函数声明 (Exported functions)-------------------------------------------*/
#if 0//0302add
extern void Bsp_Init(void);
extern void Bsp_Cycle_1ms(void);
extern void Bsp_Cycle_10ms(void);
extern void Bsp_Cycle_100ms(void);
extern void Bsp_Cycle_1000ms(void);
extern void Bsp_RtcCycle_1000ms(void);
//
extern void Bsp_Debug_100ms(void);
extern void Bsp_DebugTestOnOff(uint8_t _uc_OnOff, void *_vp_context);
extern void Bsp_Debug_IAP(uint8_t _uc_OnOff, void *_vp_context);
extern void Bsp_Debug_Write_Info(uint8_t _uc_OnOff, void *_vp_context);
//
void BspAdc_Update(void);
void BspAdc_DebugTestOnOff(uint8_t OnOff, void *_vp_context);
//
void Bsp_LedDebugTestOnOff(uint8_t _uc_trueOrFalse, void *_vp_context);
#endif
//------------------------------------------------------------------
#endif
/***************************** (END OF FILE) *********************************/
